#ifndef WXSRESOURCEFACTORY_H
#define WXSRESOURCEFACTORY_H

#include <wx/string.h>
#include <wx/menu.h>
#include "prep.h"

class wxsResource;
class wxsProject;

class wxsResourceFactory {
  public:
    static wxsResource* Build( const wxString& ResourceType, wxsProject* Project );
    static bool CanHandleExternal( const wxString& FileName );
    static wxsResource* BuildExternal( const wxString& FileName );
    static void BuildSmithMenu( wxMenu* menu );
    static bool NewResourceMenu( int Id, wxsProject* Project );
    static int ResourceTreeIcon( const wxString &ResourceType );
    static void OnAttachAll();
    static void OnReleaseAll();
  protected:
    wxsResourceFactory();
    virtual ~wxsResourceFactory();
    virtual void OnAttach() {}
    virtual void OnRelease() {}
    virtual int OnGetCount() = 0;
    virtual void OnGetInfo( int Number, wxString& Name, wxString& GUI ) = 0;
    virtual wxsResource* OnCreate( int Number, wxsProject* Project ) = 0;
    virtual bool OnCanHandleExternal( M_Code_unused const wxString& FileName ) { return false; }
    virtual wxsResource* OnBuildExternal( M_Code_unused const wxString& FileName ) { return 0; }
    virtual bool OnNewWizard( M_Code_unused int Number, wxsProject* Project ) = 0;
    virtual int OnResourceTreeIcon( M_Code_unused int Number ) { return -1; }
  private:
    struct ResourceInfo {
      wxsResourceFactory* m_Factory;
      int m_Number;
      wxString m_GUI;
      int m_MenuId;
      ResourceInfo(): m_Factory( 0 ), m_Number( 0 ), m_MenuId( -1 ) {}
    };

    WX_DECLARE_STRING_HASH_MAP( ResourceInfo, HashT );
    wxsResourceFactory* m_Next;
    bool m_Attached;
    static wxsResourceFactory* m_UpdateQueue;
    static wxsResourceFactory* m_Initialized;
    static HashT m_Hash;
    static wxString m_LastExternalName;
    static wxsResourceFactory* m_LastExternalFactory;
    static bool m_AllAttached;
    static void InitializeFromQueue();
    inline void Initialize();

};

#endif
